package com.csp.mingyue.push.controller;

import com.csp.mingyue.common.core.vo.R;
import com.csp.mingyue.push.mq.producer.KafkaProducer;
import com.csp.mingyue.push.mq.producer.RocketMqProducer;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * MQ Demo接口
 *
 * @author Strive
 * @date 2023/9/21 17:16
 */
@Slf4j
@Tag(name = "MQ Demo接口")
@Validated
@RestController
@RequestMapping("mqDemo")
@RequiredArgsConstructor
public class MqDemoController {

	private final RocketMqProducer rocketMqProducer;

	private final KafkaProducer kafkaProducer;

	@GetMapping("/sendRocketMq")
	@Operation(summary = "发送消息到RocketMQ",
			parameters = { @Parameter(name = "msg", description = "推送的消息体", required = true) })
	public R<Void> sendRocketMq(String msg) {
		rocketMqProducer.rocketMqDemoMsg(msg);
		return R.ok();
	}

	@GetMapping("/sendKafka")
	@Operation(summary = "发送消息到Kafka",
			parameters = { @Parameter(name = "msg", description = "推送的消息体", required = true) })
	public R<Void> sendKafka(String msg) {
		kafkaProducer.kafkaDemoMsg(msg);
		return R.ok();
	}

}
